%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% TxT Principal Components
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [f,l,e,vnt] = pct(x,k)

[t,n] = size(x);
x = x - repmat(mean(x),t,1);
vx = x*x'/n;
[ve, va, ve1] = svd(vx);

if k~=0; ve = ve(:,1:k);
         f = ve.*sqrt(t);
         l = x'*f/t;
         e = x-f*l';
         vnt = va(1:k,1:k);
else e = x; 
     f = zeros(t,1);
     l = zeros(n,1);
     vnt = 0;
end

